// request 是我们封装的一个网络请求库
import request from './../utils/request';
import config from './../config';
import {
    empty,
    message,
} from './../utils/helper';

const url = config.service.host;

// 提交表单
export function submitAdvisory(params, cb = {}) {
    const f = Object.assign({
        success: function(res) {
            console.log(res)
        },
        fail: function(res) {
            message(res.msg)
        },
        complete: function(res) {}
    }, cb);
    request(`${url}/Order/submitAdvisory`, params).then((res) => {
        if (typeof res == "object") {
            if (res.status == "OK") {
                f.success(res);
            } else {
                f.fail(res);
            }
            f.complete(res);
        } else {
            console.warn(res);
        }
    })
}

// 获取微信用户绑定的手机号
export function getPhoneNumber(params, cb = {}) {
    const f = Object.assign({
        success: function (res) {
            console.log(res)
        },
        fail: function (res) {
            message(res.msg)
        },
        complete: function (res) { }
    }, cb);
    request(`${url}/index/getPhoneNumber`, params).then((res) => {
        if (typeof res == "object") {
            if (res.status == "OK") {
                f.success(res);
            } else {
                f.fail(res);
            }
            f.complete(res);
        } else {
            console.warn(res);
        }
    })
}

// 微信支付
export function wxPayment(res, obj) {
    if (!empty(res)) {
        wx.requestPayment({
            'timeStamp': res.timeStamp,
            'nonceStr': res.nonceStr,
            'package': res.package,
            'signType': res.signType,
            'paySign': res.paySign,
            'success': function (res) {
                obj.success(res);
            },
            'fail': function (res) {
                obj.fail(res);
            },
            'complete': function (res) {
                obj.complete(res);
            },
        });
    }
}